/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Merlion.MRP.entity;

import Merlion.SCM.entity.InventoryBatchEntity;
import Merlion.SCM.entity.PickingOrderEntryEntity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

@Entity
public class ReservationEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private Long productId;
    private int quantity;
    private String status;
    private boolean voided;
    private boolean picked;
    @ManyToOne
    private BackOrderEntity backOrderEntity;
    private Long boId;
    @ManyToOne
    private PlannedDailyDemandEntity plannedDailyDemandEntity;
    @ManyToOne
    private InventoryBatchEntity inventoryBatch;
    @OneToOne
    private UnplannedDailyDemandEntity unplannedDailyDemand;
    @OneToOne(mappedBy = "reservationEntity")
    private PickingOrderEntryEntity poeEntry;

    public ReservationEntity() {
    }

    public void reservePlannedDemand(Long productId, int quantity, BackOrderEntity backOrderEntity, PlannedDailyDemandEntity plannedDailyDemandEntity) {
        this.productId = productId;
        this.quantity = quantity;
        this.plannedDailyDemandEntity = plannedDailyDemandEntity;
        this.backOrderEntity = backOrderEntity;
        this.boId = backOrderEntity.getId();
        this.picked = false;
        this.voided = false;
    }

    public void reserveInventoryBatch(Long productId, int quantity, BackOrderEntity bo, InventoryBatchEntity inventoryBatch) {
        this.productId = productId;
        this.quantity = quantity;
        this.inventoryBatch = inventoryBatch;
        this.backOrderEntity = bo;
        this.boId = bo.getId();
        this.picked = false;
        this.voided = false;
    }

    public void reserveUnplannedDemand(Long productId, int quantity, BackOrderEntity backOrderEntity, UnplannedDailyDemandEntity unplannedDailyDemand) {
        this.productId = productId;
        this.quantity = quantity;
        this.backOrderEntity = backOrderEntity;
        this.boId = backOrderEntity.getId();
        this.unplannedDailyDemand = unplannedDailyDemand;
        this.picked = false;
        this.voided = false;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public UnplannedDailyDemandEntity getUnplannedDailyDemand() {
        return unplannedDailyDemand;
    }

    public void setUnplannedDailyDemand(UnplannedDailyDemandEntity unplannedDailyDemand) {
        this.unplannedDailyDemand = unplannedDailyDemand;
    }

    public Long getBoId() {
        return boId;
    }

    public void setBoId(Long boId) {
        this.boId = boId;
    }

    public PickingOrderEntryEntity getPoeEntry() {
        return poeEntry;
    }

    public void setPoeEntry(PickingOrderEntryEntity poeEntry) {
        this.poeEntry = poeEntry;
    }

    public BackOrderEntity getBackOrderEntity() {
        return backOrderEntity;
    }

    public void setBackOrderEntity(BackOrderEntity backOrderEntity) {
        this.backOrderEntity = backOrderEntity;
    }

    public Long getProductId() {
        return productId;
    }

    public void setProductId(Long productId) {
        this.productId = productId;
    }

    public InventoryBatchEntity getInventoryBatch() {
        return inventoryBatch;
    }

    public void setInventoryBatch(InventoryBatchEntity inventoryBatch) {
        this.inventoryBatch = inventoryBatch;
    }

    public PlannedDailyDemandEntity getPlannedDailyDemandEntity() {
        return plannedDailyDemandEntity;
    }

    public void setPlannedDailyDemandEntity(PlannedDailyDemandEntity plannedDailyDemandEntity) {
        this.plannedDailyDemandEntity = plannedDailyDemandEntity;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public boolean isVoided() {
        return voided;
    }

    public void setVoided(boolean voided) {
        this.voided = voided;
    }

    public boolean isPicked() {
        return picked;
    }

    public void setPicked(boolean picked) {
        this.picked = picked;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ReservationEntity)) {
            return false;
        }
        ReservationEntity other = (ReservationEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.scm.ReservationEntity[ id=" + id + " ]";
    }
}
